<?php

namespace App\ModelFilters;


use App\Models\SysDept;

class SysUserFilter extends BaseFilter
{
    /**
    * Related Models that have ModelFilters as well as the method on the ModelFilter
    * As [relationMethod => [input_key1, input_key2]].
    *
    * @var array
    */
    public $relations = [
    ];

    public function username($value){
        return $this->where('username','LIKE', "%$value%");
    }

    public function nickname($value){
        return $this->where('nickname','LIKE', "%$value%");
    }
    public function group_id($value){
        return $this->where('group_id',$value);
    }

    public function dept_id($value){
        $result_1 = SysDept::ancestorsAndSelf($value)->pluck('id');
        $result_2 = SysDept::descendantsOf($value)->pluck('id');
        $result = array_merge($result_1->toArray(), $result_2->toArray());
        return $this->whereIn('dept_id', $result);
    }
    public function user_type($value){
        return $this->where('user_type', $value);
    }

    public function status($value){
        return $this->where('status', $value);
    }

}
